package com.loyal.camerax.config

import android.graphics.Bitmap

/**压缩配置*/
data class CompressConfig(
    /**是否可压缩*/
    var enable: Boolean = false,
    /**图片质量压缩*/
    val quality: Int = PICTURE_QUALITY,
    /**图片大小限制100k以内*/
    val maxSize: Int = 100,
    /**压缩格式*/
    val format: Bitmap.CompressFormat = Bitmap.CompressFormat.JPEG,
    var byteDate: ByteArray? = null,
) {
    companion object {
        /**
         * 图片质量
         */
        const val PICTURE_QUALITY: Int = 75
        const val PICTURE_QUALITY_INTERVAL: Int = 5
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is CompressConfig) return false

        if (enable != other.enable) return false
        if (quality != other.quality) return false
        if (format != other.format) return false
        if (byteDate != null) {
            if (other.byteDate == null) return false
            if (!byteDate.contentEquals(other.byteDate)) return false
        } else if (other.byteDate != null) return false

        return true
    }

    override fun hashCode(): Int {
        var result = enable.hashCode()
        result = 31 * result + quality
        result = 31 * result + format.hashCode()
        result = 31 * result + (byteDate?.contentHashCode() ?: 0)
        return result
    }
}
